/*
client_proc.dm
All of the built in procs for clients that are overriden, as well as the procs made by us. Most procs we make
are actually more suited for a global proc, though, so there won't be many here.
*/

client

	//overriden move just checks for start/end (building vars) and if you can move
	Move(loc,dir)
		images=list()
		if(!mob.canMove)
			if(start && end)return
			else mob.canMove=1
		.=..()

	//load_screen() loads the "alert" dialog in the beginning
	New()
		..()
		load_screen()

	//just cleaning up after the person logs out
	Del()
		Save()
		world << format_server("[mob] has left the world.")
		del mob
		..()

	//well, I don't want the server filling up with peoples large icon files :|
	AllowUpload(filename, filelength)
		if(filelength >= 524288)
			src << "[filename] is too big to upload!"
			return 0
		return 1

	//the beginning of a build drag/drop
	MouseDown(object,location,control,params)
		if(isturf(location))
			var/turf/t = location
			start=t

	//the middle part of building with drag/drop - showing the graphics as you drag
	MouseDrag(src_object,over_object,src_location,over_location,src_control,over_control,params)
		..()
		if(!istype(src_object, /obj/builditems)) return
		if(isturf(over_location))
			mob.canMove=FALSE
			var/turf/t = over_location
			end=t
			switch(mob.buildmode)
				if("Building","Copy")
					images=list()
					if(!mob.current_item)return
					var/obj/o = new mob.current_item
					o.icon = mouse_pointer_icon
					for(var/turf/tt in block(start,end))
						images += image(icon=o.icon, loc=tt, icon_state=o.icon_state, layer=FLY_LAYER+4)
				else
					images=list()
					for(var/turf/tt in block(start,end))
						images += image(icon='base.dmi', loc=tt, icon_state="cover", layer=FLY_LAYER+4)

	//the end of drag/drop - actually making the objects
	MouseDrop(src_object,over_object,src_location,over_location,src_control,over_control,params)
		..()
		images=list()
		mob.canMove=TRUE
		if(start && end)
			switch(mob.buildmode)
				if("Building","Copy")
					for(var/turf/t in block(start,end))
						if(isbuildable(t))
							var/mob/player/m = mob
							if(!mob.current_item)return
							var/obj/builditems/new_item=new mob.current_item(loc=t,owner=ckey,name=m.cur_name, iconstate=m.cur_state, iconfile=m.cur_file)

							new_item.icon = mouse_pointer_icon
							if(mob.buildmode=="Copy")
								var/mob/player/p=mob
								var/obj/builditems/b = locate(new_item.type) in p.clipboard
								if(!b)continue
								for(var/o in b.vars)
									if(o!="builtowner" && o!="loc" && o!="x" && o!="y" && o!="z" && o!="uid" && !(islist(b.vars[o])) && !(ispath(b.vars[o])))new_item.vars[o]=b.vars[o]

				else
					var/change
					switch(mob.buildmode)
						if("Layer")
							switch(input(src,"What layer would you like it on?")in null|list("Mob level","Below Mobs","Above Mobs","Cancel"))
								if("Mob level") change=MOB_LAYER
								if("Below Mobs")change=MOB_LAYER-1
								if("Above Mobs")change=MOB_LAYER+1
							for(var/turf/t in block(start,end))
								if(isbuildable(t))for(var/obj/builditems/o in t.contents)
									if(o.builtowner==ckey || adminMode)
										o.layer=change
										o.save(mob.buildmode, change)
						if("Opacity")
							switch(input(src,"What opacity would you like?")in null|list("Opaque","Not Opaque","Auto","Cancel"))
								if("Opaque") 	change=1
								if("Not Opaque")change=0
								if("Auto")		change="a"
							for(var/turf/t in block(start,end))
								if(isbuildable(t))for(var/obj/builditems/o in t.contents)
									if(o.builtowner==ckey || adminMode)
										o.opacity= change=="a" ? !o.opacity : change
										o.save(mob.buildmode, o.opacity)
						if("Luminosity")
							change=input(src,"How much light should they give off? (in tiles)")as null|num
							for(var/turf/t in block(start,end))
								if(isbuildable(t))for(var/obj/builditems/o in t.contents)
									if(o.builtowner==ckey || adminMode)
										o.luminosity = change
										o.save(mob.buildmode, change)

						if("Infra Luminosity")
							change=input(src,"How visible are they in the dark? (in tiles)")as null|num
							for(var/turf/t in block(start,end))
								if(isbuildable(t))for(var/obj/builditems/o in t.contents)
									if(o.builtowner==ckey || adminMode)
										o.infra_luminosity = change
										o.save(mob.buildmode, change)

						if("Density")
							switch(input(src,"What density would you like?")in list("Dense","Not Dense","Auto","Cancel"))
								if("Dense") 	change=1
								if("Not Dense")	change=0
								if("Auto")		change="a"
							for(var/turf/t in block(start,end))
								if(isbuildable(t))for(var/obj/builditems/o in t.contents)
									if(o.builtowner==ckey || adminMode)
										o.density= change=="a" ? !o.density : change
										o.save(mob.buildmode, o.density)
						if("Deletion")
							for(var/turf/t in block(start,end))
								if(isbuildable(t))for(var/obj/builditems/o in t.contents)
									if(o.builtowner==ckey || adminMode)
										if(o.builtowner)o.deletion()

						if("Delete Tiles")
							src << "Sorry, this mode doesn't work with drag & drop. Use Deletion."
			start=null
			end=null
